<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="产品名称" prop="fprProname">
        <el-input
          v-model="queryParams.fprProname"
          placeholder="请输入产品名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item class="longLabel" label="金融机构名称" prop="fprFinancename">
        <el-input
          v-model="queryParams.fprFinancename"
          placeholder="请输入金融机构名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['financeProduct:product:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['financeProduct:product:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['financeProduct:product:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['financeProduct:product:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="productList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="产品名称" align="center" prop="fprProname" />

      <el-table-column label="金融机构编号" align="center" prop="fprFinanceid"></el-table-column>
      <el-table-column label="金融机构名称" align="center" prop="fprFinancename" />
      <el-table-column label="操作员" align="center" prop="fprUserno" />

      <el-table-column label="贷款期限范围(月)" align="center" prop="fprLoandateRange" />
      <el-table-column label="利率范围" align="center" prop="fprBeginrateRange" />
      <!-- <el-table-column label="利率结束(%)" align="center" prop="fprEndrate" /> -->
      <el-table-column label="贷款额度范围(万元)" align="center" prop="fprLoanamtRange"></el-table-column>
      <el-table-column label="担保类型" align="center" prop="fprGuatype">
        <template slot-scope="{row}">
          <span v-if="row.fprGuatype == 9">不限</span>
          <span v-if="row.fprGuatype === '0'">抵押</span>
          <span v-if="row.fprGuatype == 1">质押</span>
          <span v-if="row.fprGuatype == 4">信用</span>
          <span v-if="row.fprGuatype == 3">一般保证</span>
        </template>
      </el-table-column>
      <el-table-column label="操作时间" align="center" prop="createTime" />
      <el-table-column label="产品状态" align="center" prop="fprStt">
        <template slot-scope="{row}">
          <span v-if="row.fprStt == 0">隐藏</span>
          <span v-if="row.fprStt == 1">发布</span>
        </template>
      </el-table-column>
      <el-table-column label="联系电话" align="center" prop="fprMoblie" />
      <!-- <el-table-column label="产品星级" align="center" prop="productStar" />
      <el-table-column label="产品评分" align="center" prop="productScore" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['financeProduct:product:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['financeProduct:product:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改金融机构发布产品对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="700px" append-to-body class="addLoan">
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="产品名称" prop="fprProname">
          <el-input v-model="form.fprProname" placeholder="请输入产品名称" />
        </el-form-item>
        <el-form-item label="金融产品类型" prop="fprFinprotype" class="rateRange">
          <el-select v-model="form.fprFinprotype" placeholder="请选择金融产品类型">
            <el-option
              v-for="item in productType"
              :key="item.key"
              :label="item.value"
              :value="item.key"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="适用区域" prop="province">
          <!-- <treeselect v-model="form.province" :multiple="true" :options="deptOptions" :normalizer="normalizer" :show-count="true" /> -->
          <el-tree :data="deptOptions" show-checkbox node-key="id" placeholder="请选择使用区域" ref="tree"></el-tree>
        </el-form-item>
        <el-form-item label="所属机构" prop="fprFinanceid">
          <el-select v-model="form.fprFinanceid" placeholder="请输入所属机构" class="input_info">
            <el-option v-for="item in organ" :key="item.key" :label="item.value" :value="item.key"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="贷款额度" :prop="showTips?'':'fprLoanamt'" ref="fprLoanamtForm">
          <el-col :span="9">
            <el-input :disabled="showTips" v-model="form.fprLoanamt" placeholder="请输入贷款额度--万元" />
          </el-col>
          <el-col :span="2" style="text-align:center">
            <span>至</span>
          </el-col>
          <el-col :span="9">
            <el-input :disabled="showTips" v-model="form.fprLoantoamt" placeholder="请输入贷款额度--万元" />
          </el-col>
          <el-col :span="3" style="margin-left:10px">
            <el-checkbox v-model="showTips">其他</el-checkbox>
          </el-col>
        </el-form-item>
        <el-form-item label="额度大写">
          <el-col :span="10" v-if="moneyCurrency">{{moneyCurrency | toChines}}</el-col>
          <el-col :span="10" v-else>未输入</el-col>
          <el-col :span="2" style="text-align:center">
            <span>至</span>
          </el-col>
          <el-col :span="12" v-if="moneyCurrency1">{{moneyCurrency1 | toChines}}</el-col>
          <el-col :span="10" v-else>未输入</el-col>
        </el-form-item>
        <el-form-item label="贷款期限" :prop="showTips1?'':'fprLoandate'" ref="fprLoandateForm">
          <el-col :span="9">
            <el-input :disabled="showTips1" v-model="form.fprLoandate" placeholder="请输入贷款期限--月" />
          </el-col>
          <el-col :span="2" style="text-align:center">
            <span>至</span>
          </el-col>
          <el-col :span="9">
            <el-input :disabled="showTips1" v-model="form.fprLoantodate" placeholder="请输入贷款期限--月" />
          </el-col>
          <el-col :span="3" style="margin-left:10px">
            <el-checkbox v-model="showTips1">其他</el-checkbox>
          </el-col>
        </el-form-item>
        <el-form-item
          class="rateRange"
          label="参考利率范围"
          :prop="showTips2?'':'fprBeginrate'"
          ref="fprBeginrateForm"
        >
          <el-col :span="9" v-if="!showTips2">
            <el-input v-model="form.fprBeginrate" placeholder="请输入利率开始--%" />
          </el-col>
          <el-col :span="2" style="text-align:center" v-if="!showTips2">
            <span>至</span>
          </el-col>
          <el-col :span="9" v-if="!showTips2">
            <el-input v-model="form.fprEndrate" placeholder="请输入利率结束--%" />
          </el-col>
          <el-col :span="20" v-if="showTips2">
            <el-input v-model="form.rateExplan" placeholder="请输入利率说明" />
          </el-col>
          <el-col :span="3" style="margin-left:10px">
            <el-checkbox v-model="showTips2">其他</el-checkbox>
          </el-col>
        </el-form-item>
        <el-form-item label="联系电话" prop="fprMoblie">
          <el-col :span="10">
            <el-input v-model="form.fprMoblie" placeholder="请输入联系电话" />
          </el-col>
        </el-form-item>
        <el-form-item label="担保类型" prop="fprGuatype">
          <el-select v-model="form.fprGuatype" placeholder="请选择担保类型">
            <el-option label="抵押" value="0" />
            <el-option label="质押" value="1" />
            <el-option label="信用" value="4" />
            <el-option label="一般保证" value="3" />
            <el-option label="不限" value="9" />
          </el-select>
        </el-form-item>
        <el-form-item label="是否显示" prop="fprStt">
          <el-radio-group v-model="form.fprStt" size="small">
            <el-radio-button label="1">是</el-radio-button>
            <el-radio-button label="0">否</el-radio-button>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="即将发布" prop="fprProducttype">
          <el-radio-group v-model="form.fprProducttype" size="small">
            <el-radio-button label="0">是</el-radio-button>
            <el-radio-button label="1">否</el-radio-button>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="申请条件" prop="fprProtype">
          <el-input v-model="form.fprProtype" type="textarea" placeholder="请输入申请条件" />
        </el-form-item>
        <el-form-item label="产品简介" prop="fprProchr">
          <el-input v-model="form.fprProchr" type="textarea" placeholder="请输入产品简介" />
        </el-form-item>
        <el-form-item label="适用客户" prop="fprLoanpurpose">
          <el-input v-model="form.fprLoanpurpose" type="textarea" placeholder="请输入适用客户" />
        </el-form-item>
        <el-form-item label="提交材料" prop="fprDesc">
          <el-input v-model="form.fprDesc" type="textarea" placeholder="请输入提交材料" />
        </el-form-item>
        <el-form-item label="产品特点" prop="fprFlow">
          <el-input v-model="form.fprFlow" type="textarea" placeholder="请输入产品特点" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listProduct,
  getProduct,
  delProduct,
  addProduct,
  updateProduct,
  exportProduct
} from "@/api/financeProduct/product";
import { listDept } from "@/api/system/dept";
import { dictType } from "@/api/system/user";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
export default {
  name: "Product",
  components: {
    Treeselect
  },

  data() {
    return {
      // 遮罩层
      loading: true,
      showTips: false,
      showTips1: false,
      showTips2: false,
      moneyCurrency1: "",
      // 选中数组
      ids: [],
      stopRepate: false,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 金融机构发布产品表格数据
      productList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        fprProname: null,
        fprProtype: null,
        fprFinanceid: null,
        fprFinancename: null,
        fprUserno: null,
        fprPropath: null,
        fprLoandate: null,
        fprBeginrate: null,
        fprEndrate: null,
        fprLoanamt: null,
        fprLoantoamt: null,
        fprGuatype: null,
        fprLoanpurpose: null,
        fprPaytype: null,
        fprStt: null,
        fprOptime: null,
        fprProchr: null,
        fprDesc: null,
        fprFlow: null,
        fprMoblie: null,
        fprLoantoamt: null,
        fprLoantodate: null,
        fprReqcount: null,
        fprEntcount: null,
        fprSucccount: null,
        fprChecktime: null,
        fprProducttype: null,
        fprMeasures: null,
        fprFinprotype: null,
        fprIsswd: null,
        frpFinancetype: null,
        frpLoanamtother: null,
        frpLoanrateother: null,
        frpLoandateother: null,
        fprInvtindustry: null,
        fprInvtstage: null,
        fprContactname: null,
        rateExplan: null,
        productArea: null,
        productStar: null,
        productScore: null,
        pushStatus: null,
        syncChannel: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        fprProname: [
          { required: true, message: "产品名称不能为空", trigger: "blur" }
        ],
        fprBeginrate: [
          { required: true, message: "利率开始--%不能为空", trigger: "blur" }
        ],
        fprEndrate: [
          { required: true, message: "利率结束--%不能为空", trigger: "blur" }
        ],
        cityId: [
          { required: true, message: "适用区域不能为空", trigger: "blur" }
        ],
        fprFinanceid: [
          { required: true, message: "所属机构不能为空", trigger: "blur" }
        ],
        fprLoanamt: [
          { required: true, message: "贷款额度不能为空", trigger: "blur" }
        ],
        fprLoandate: [
          { required: true, message: "贷款期限不能为空", trigger: "blur" }
        ],
        fprMoblie: [
          { required: true, message: "联系电话不能为空", trigger: "blur" }
        ],
        fprGuatype: [
          { required: true, message: "担保类型不能为空", trigger: "blur" }
        ],
        fprFinprotype: [
          { required: true, message: "金融产品类型不能为空", trigger: "blur" }
        ],
        fprStt: [
          { required: true, message: "是否显示不能为空", trigger: "blur" }
        ],
        fprProducttype: [
          { required: true, message: "即将发布不能为空", trigger: "blur" }
        ]
      },
      moneyCurrency: "",
      cityList: [
        {
          label: "安徽省",
          id: "-1",
          children: [
            {
              label: "合肥市",
              id: "340100",
              children: [
                { id: "340102", label: "瑶海区" },
                { id: "340103", label: "庐阳区" },
                { id: "340104", label: "蜀山区" },
                { id: "340111", label: "包河区" },
                { id: "340121", label: "长丰县" },
                { id: "340122", label: "肥东县" },
                { id: "340123", label: "肥西县" },
                { id: "340124", label: "庐江县" },
                { id: "340181", label: "巢湖市" }
              ]
            },
            {
              label: "芜湖市",
              id: "340200",
              children: [
                { id: "340202", label: "镜湖区" },
                { id: "340203", label: "弋江区" },
                { id: "340207", label: "鸠江区" },
                { id: "340208", label: "三山区" },
                { id: "340221", label: "芜湖县" },
                { id: "340222", label: "繁昌县" },
                { id: "340223", label: "南陵县" },
                { id: "340225", label: "无为县" }
              ]
            },
            {
              label: "蚌埠市",
              id: "340300",
              children: [
                { id: "340302", label: "龙子湖区" },
                { id: "340303", label: "蚌山区" },
                { id: "340304", label: "禹会区" },
                { id: "340311", label: "淮上区" },
                { id: "340321", label: "怀远县" },
                { id: "340322", label: "五河县" },
                { id: "340323", label: "固镇县" }
              ]
            },
            {
              label: "淮南市",
              id: "340400",
              children: [
                { id: "340402", label: "大通区" },
                { id: "340403", label: "田家庵区" },
                { id: "340404", label: "谢家集区" },
                { id: "340405", label: "八公山区" },
                { id: "340406", label: "潘集区" },
                { id: "340421", label: "凤台县" },
                { id: "340422", label: "寿县" }
              ]
            },
            {
              label: "马鞍山市",
              id: "340500",
              children: [
                { id: "340503", label: "花山区" },
                { id: "340504", label: "雨山区" },
                { id: "340506", label: "博望区" },
                { id: "340521", label: "当涂县" },
                { id: "340522", label: "含山县" },
                { id: "340523", label: "和县" }
              ]
            },
            {
              label: "淮北市",
              id: "340600",
              children: [
                { id: "340602", label: "杜集区" },
                { id: "340603", label: "相山区" },
                { id: "340604", label: "烈山区" },
                { id: "340621", label: "濉溪县" }
              ]
            },
            {
              label: "铜陵市",
              id: "340700",
              children: [
                { id: "340705", label: "铜官区" },
                { id: "340711", label: "郊区" },
                { id: "340706", label: "义安区" },
                { id: "340722", label: "枞阳县" }
              ]
            },
            {
              label: "安庆市",
              id: "340800",
              children: [
                { id: "340802", label: "迎江区" },
                { id: "340803", label: "大观区" },
                { id: "340811", label: "宜秀区" },
                { id: "340822", label: "怀宁县" },
                { id: "340824", label: "潜山县" },
                { id: "340825", label: "太湖县" },
                { id: "340826", label: "宿松县" },
                { id: "340827", label: "望江县" },
                { id: "340828", label: "岳西县" },
                { id: "340881", label: "桐城市" }
              ]
            },
            {
              label: "黄山市",
              id: "341000",
              children: [
                { id: "341002", label: "屯溪区" },
                { id: "341003", label: "黄山区" },
                { id: "341004", label: "徽州区" },
                { id: "341021", label: "歙县" },
                { id: "341022", label: "休宁县" },
                { id: "341023", label: "黟县" },
                { id: "341024", label: "祁门县" }
              ]
            },
            {
              label: "滁州市",
              id: "341100",
              children: [
                { id: "341102", label: "琅琊区" },
                { id: "341103", label: "南谯区" },
                { id: "341122", label: "来安县" },
                { id: "341124", label: "全椒县" },
                { id: "341125", label: "定远县" },
                { id: "341126", label: "凤阳县" },
                { id: "341181", label: "天长市" },
                { id: "341182", label: "明光市" }
              ]
            },
            {
              label: "阜阳市",
              id: "341200",
              children: [
                { id: "341202", label: "颍州区" },
                { id: "341203", label: "颍东区" },
                { id: "341204", label: "颍泉区" },
                { id: "341221", label: "临泉县" },
                { id: "341222", label: "太和县" },
                { id: "341225", label: "阜南县" },
                { id: "341226", label: "颍上县" },
                { id: "341282", label: "界首市" }
              ]
            },
            {
              label: "宿州市",
              id: "341300",
              children: [
                { id: "341302", label: "埇桥区" },
                { id: "341321", label: "砀山县" },
                { id: "341322", label: "萧县" },
                { id: "341323", label: "灵璧县" },
                { id: "341324", label: "泗县" }
              ]
            },
            {
              label: "六安市",
              id: "341500",
              children: [
                { id: "341502", label: "金安区" },
                { id: "341503", label: "裕安区" },
                { id: "341522", label: "霍邱县" },
                { id: "341523", label: "舒城县" },
                { id: "341524", label: "金寨县" },
                { id: "341525", label: "霍山县" },
                { id: "341504", label: "叶集区" }
              ]
            },
            {
              label: "亳州市",
              id: "341600",
              children: [
                { id: "341602", label: "谯城区" },
                { id: "341621", label: "涡阳县" },
                { id: "341622", label: "蒙城县" },
                { id: "341623", label: "利辛县" }
              ]
            },
            {
              label: "池州市",
              id: "341700",
              children: [
                { id: "341702", label: "贵池区" },
                { id: "341721", label: "东至县" },
                { id: "341722", label: "石台县" },
                { id: "341723", label: "青阳县" }
              ]
            },
            {
              label: "宣城市",
              id: "341800",
              children: [
                { id: "341802", label: "宣州区" },
                { id: "341821", label: "郎溪县" },
                { id: "341822", label: "广德县" },
                { id: "341823", label: "泾县" },
                { id: "341824", label: "绩溪县" },
                { id: "341825", label: "旌德县" },
                { id: "341881", label: "宁国市" }
              ]
            }
          ]
        }
      ],
      deptOptions: undefined,
      organ: [],
      productType: []
    };
  },
  created() {
    this.getList();
    this.getList2();
    this.loanWay();
    this.deptOptions = this.cityList;
  },
  methods: {
    /** 查询部门列表 */
    getList2() {
      this.loading = true;
      var param = {
        parentId: "13"
      };
      listDept(param).then(response => {
        response.data.forEach(element => {
          this.organ.push({ key: element.financeId, value: element.deptName });
        });
      });
    },
    loanWay() {
      dictType("product_type").then(res => {
        res.data.forEach(element => {
          this.productType.push({
            key: element.dictValue,
            value: element.dictLabel
          });
        });
      });
    },
    /** 查询金融机构发布产品列表 */
    getList() {
      this.loading = true;
      listProduct(this.queryParams).then(response => {
        this.productList = response.rows;
        this.productList.forEach(element => {
          if (element.frpLoanrateother == "0") {
            element.fprBeginrateRange =
              element.fprBeginrate + "% -" + element.fprEndrate + "%";
          } else {
            element.fprBeginrateRange = element.rateExplan;
          }
          if (element.frpLoanamtother == "0") {
            element.fprLoanamtRange =
              element.fprLoanamt / 10000 + "-" + element.fprLoantoamt / 10000;
          } else {
            element.fprLoanamtRange = "不限";
          }
          if (element.frpLoandateother == "0") {
            element.fprLoandateRange =
              element.fprLoandate + "-" + element.fprLoantodate;
          } else {
            element.fprLoandateRange = "不限";
          }
        });
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      (this.showTips = false),
        (this.showTips1 = false),
        (this.showTips2 = false),
        (this.form = {
          fprFlowno: null,
          fprProname: null,
          fprProtype: null,
          fprFinanceid: null,
          fprFinancename: null,
          fprUserno: null,
          fprPropath: null,
          fprLoandate: null,
          fprBeginrate: null,
          fprEndrate: null,
          fprLoanamt: "",
          fprGuatype: null,
          fprLoanpurpose: null,
          fprPaytype: null,
          fprStt: null,
          fprOptime: null,
          fprProchr: null,
          fprDesc: null,
          fprFlow: null,
          fprMoblie: null,
          fprLoantoamt: "",
          fprLoantodate: null,
          fprReqcount: null,
          fprEntcount: null,
          fprSucccount: null,
          fprChecktime: null,
          fprProducttype: null,
          fprMeasures: null,
          fprFinprotype: null,
          fprIsswd: null,
          frpFinancetype: null,
          frpLoanamtother: null,
          frpLoanrateother: null,
          frpLoandateother: null,
          fprInvtindustry: null,
          fprInvtstage: null,
          fprContactname: null,
          rateExplan: null,
          productArea: null,
          productStar: null,
          productScore: null,
          pushStatus: "0",
          syncChannel: null
        });
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.fprFlowno);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.$nextTick(() => {
        this.$refs.tree.setCheckedKeys([]);
      });
      this.open = true;
      this.title = "添加金融机构发布产品";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const fprFlowno = row.fprFlowno || this.ids;
      getProduct(fprFlowno).then(response => {
        this.form = response.data;
        this.open = true;
        let list1 = [];
        this.title = "修改金融机构发布产品";
        if (response.data.productAreaVo.province == "-1") {
          this.$nextTick(() => {
            this.$refs.tree.setCheckedKeys(["-1"]);
          });
        }
        if (response.data.fprLoanamt) {
          this.form.fprLoanamt = parseFloat(response.data.fprLoanamt) / 10000;
        }
        if (response.data.fprLoantoamt) {
          this.form.fprLoantoamt =
            parseFloat(response.data.fprLoantoamt) / 10000;
        }
        if (response.data.productAreaVo.city) {
          let list2 = response.data.productAreaVo.city.split(",");
          list2.forEach(element => {
            list1.push(element);
          });
          this.$nextTick(() => {
            this.$refs.tree.setCheckedKeys(list1);
          });
        }
        if (response.data.frpLoanamtother == 1) {
          this.showTips = true;
        }
        if (response.data.frpLoandateother == 1) {
          this.showTips1 = true;
        }
        if (response.data.frpLoanrateother == 1) {
          this.showTips2 = true;
        }
        if (response.data.productAreaVo.district) {
          let list3 = response.data.productAreaVo.district.split(",");
          list3.forEach(element => {
            list1.push(element);
          });
          this.$nextTick(() => {
            this.$refs.tree.setCheckedKeys(list1);
          });
        }
      });
    },

    /** 提交按钮 */
    submitForm() {
      if (this.stopRepate) {
        this.$message({ message: "重复点击，请稍后等待结果", type: "info" });
        return;
      }

      this.$refs["form"].validate(valid => {
        if (this.showTips) {
          this.$refs["fprLoanamtForm"].clearValidate();
          this.form.frpLoanamtother = "1";
        } else {
          this.form.frpLoanamtother = "0";
        }
        if (this.showTips1) {
          this.$refs["fprLoandateForm"].clearValidate();
          this.form.frpLoandateother = "1";
        } else {
          this.form.frpLoandateother = "0";
        }
        if (this.showTips2) {
          this.$refs["fprBeginrateForm"].clearValidate();
          this.form.frpLoanrateother = "1";
        } else {
          this.form.frpLoanrateother = "0";
        }
        if (valid) {
          this.stopRepate = true;
          if (this.form.fprFlowno != null) {
            var str = "-1";
            let list = [];
            if (this.$refs.tree.getCheckedKeys().indexOf(str) != -1) {
              this.form.province = "-1";
            } else {
              this.$refs.tree.getCheckedKeys().forEach(element => {
                if (element.slice(4, 6) == "00") {
                  list.push(element);
                }
                if (
                  this.$refs.tree
                    .getCheckedKeys()
                    .indexOf(element.slice(0, 4) + "00") == -1
                ) {
                  list.push(element);
                }
              });
              this.form.province = list.join(",");
            }
            if (this.form.fprLoanamt) {
              this.form.fprLoanamt = parseFloat(this.form.fprLoanamt) * 10000;
            }
            if (this.form.fprLoantoamt) {
              this.form.fprLoantoamt =
                parseFloat(this.form.fprLoantoamt) * 10000;
            }
            this.loading = true;
            updateProduct(this.form).then(response => {
              this.loading = false;
              this.stopRepate = false;
              if (response.code == "200") {
                this.msgSuccess("修改成功");
              } else {
                this.$message({ message: res.msg, type: "error" });
              }
              this.open = false;
              this.getList();
            });
          } else {
            // this.form.province = this.form.province.join(',')
            var str = "-1";
            let list = [];
            if (this.$refs.tree.getCheckedKeys().indexOf(str) != -1) {
              this.form.province = "-1";
            } else {
              this.$refs.tree.getCheckedKeys().forEach(element => {
                if (element.slice(4, 6) == "00") {
                  list.push(element);
                }
              });
              this.form.province = list.join(",");
            }
            if (this.form.fprLoanamt) {
              this.form.fprLoanamt = parseFloat(this.form.fprLoanamt) * 10000;
            }
            if (this.form.fprLoantoamt) {
              this.form.fprLoantoamt =
                parseFloat(this.form.fprLoantoamt) * 10000;
            }
            this.loading = true;
            addProduct(this.form).then(response => {
              this.loading = false;
              this.stopRepate = false;
              if (response.code == "200") {
                this.msgSuccess("新增成功");
              } else {
                this.$message({ message: res.msg, type: "error" });
              }
              this.open = false;
              this.getList();
              this.$refs.tree.setCheckedKeys([]);
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const fprFlownos = row.fprFlowno || this.ids;
      this.$confirm(
        '是否确认删除金融机构发布产品编号为"' + fprFlownos + '"的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }
      )
        .then(function() {
          return delProduct(fprFlownos);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有金融机构发布产品数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(function() {
          return exportProduct(queryParams);
        })
        .then(response => {
          this.download(response.msg);
        });
    }
  },
  watch: {
    showTips() {
      if (this.showTips) {
        this.$refs["fprLoanamtForm"].clearValidate();
        this.form.fprLoanamt = "";
        this.form.fprLoantoamt = "";
      }
    },
    showTips1() {
      if (this.showTips1) {
        this.$refs["fprLoandateForm"].clearValidate();
        this.form.fprLoandate = "";
        this.form.fprLoantodate = "";
      }
    },
    showTips2() {
      if (this.showTips2) {
        this.$refs["fprBeginrateForm"].clearValidate();
        this.form.fprBeginrate = "";
        this.form.fprEndrate = "";
        if (this.form.rateExplan) {
        } else {
          this.form.rateExplan = "一户一价";
        }
      }
    },
    "form.fprLoanamt"(newVal, oldVal) {
      if (newVal.length > 8) {
        this.form.fprLoanamt = "";
        this.$message.error("请输入正确的金额");
      } else {
        this.moneyCurrency = newVal;
      }
    },
    "form.fprLoantoamt"(newVal, oldVal) {
      if (newVal.length > 8) {
        this.form.fprLoantoamt = "";
        this.$message.error("请输入正确的金额");
      } else {
        this.moneyCurrency1 = newVal;
      }
    }
  },
  filters: {
    //局部过滤器
    toChines: function(num) {
      //形参
      var chnNum = ["零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"];
      var chnUnit = ["", "亿", "兆", "京"]; //前面的空串是为了匹配个位的单位，单位"京"的后面可以继续扩展
      var chnUnitNumber = ["", "拾", "佰", "仟"];

      var numArr = [];
      var number = [];
      for (var i = 0; num > 0; i++) {
        var x = num % 10000;
        num = Math.floor(num / 10000);
        numArr.unshift(x);
        number.unshift(x);
      }
      // var numArr = this.numSplit(num);
      var strArr = [];
      for (var j = 0; j < numArr.length; j++) {
        //正确读出4位数的读法
        var strr = "";
        var flag = true;
        for (var i = 0; numArr[j] > 0; i++) {
          var s = numArr[j] % 10;
          numArr[j] = Math.floor(numArr[j] / 10);
          if (j == 0 && s == 0) {
            flag = false;
            continue;
          } else if (s == 0) {
            if (flag) {
              strr = chnNum[s] + strr;
              flag = false;
            }
          } else {
            flag = true;
            strr = chnNum[s] + chnUnitNumber[i] + strr;
          }
        }
        strArr.push(strr);
      }
      var str = "";
      var len = number.length;
      var flag = true;
      for (var x = len - 1, y = 0; x >= 0; x--, y++) {
        if (number[x] == 0) {
          continue;
        } else if (x != 0 && number[x] < 1000) {
          str = chnNum[0] + strArr[x] + chnUnit[y] + str;
        } else {
          str = strArr[x] + chnUnit[y] + str;
        }
      }
      return str + "万元整";
    }
  }
};
</script>
<style>
.longLabel label {
  width: 100px !important;
}
.rateRange label {
  line-height: 20px !important;
}
.addLoan /deep/ .el-dialog {
  display: flex;
  flex-direction: column;
  margin: 0 !important;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  max-height: calc(100% -30px);
  /* max-width: ; */
}
.addLoan /deep/ .el-dialog__body {
  height: 380px;
  overflow-y: auto;
  padding-top: 0;
}
</style>
